require(['loading'], function(loading) {
	//获取url中的id参数
	var params = getUrlParams();
	var id = params.id ? params.id : "";
	var isFollow;
	var type;

	//应用实例化
	var buyDetail = new Vue({
		el: '#buyDetail',
		data: {
			detailsData: [],
			showLoading: false,
			apiUrl: wxUrl + '/v3.3/tbuyingInfo/detail',
			fllowUrl: wxUrl + '/v3.3/tbuyingInfo/collection',
			item: {
				params: {
					token: token,
					userToken: userToken,
					id: id
				}
			},
			item2: {
				params: {
					token: token,
					userToken: userToken,
					id: id,
					type: true
				}
			}
		},
		ready: function() {
			this.getDetailData();
		},
		methods: {
			getDetailData: function() {
				this.$http.get(this.apiUrl, this.item)
				.then(function(response) {
					var result = JSON.parse(response.body);
					var detailData = result.data.tBuyingInfo;
					var headPic = result.data.headPic;
					var categoryName= result.data.categoryName;
					if(typeof headPic == undefined){
						$("#headPic").attr("src","");
					}else{
						$("#headPic").attr("src",headPic);
					}
					if(categoryName == '' || categoryName == null || categoryName == undefined){
						$("#categoryName").text("未知");
					}else{
						$("#categoryName").text(categoryName);
					}
					this.$set('detailData', detailData);
					var address = detailData.buyerAddress;
					if(address == '' || address == null || address == undefined){
						$(".wz_userAddr").text("未知");
					}else{
						$(".wz_userAddr").text(address);
					}
					//是否收藏
					isFollow = result.data.isCollection;
					if(isFollow == '0') {
						this.item2.params.type = false;
						$(".bulk_foot .bulk_gz").html('<img src="../static/images/keep_r1.png" alt="" /><span>收藏</span>');
					} else if(isFollow == '1') {
						this.item2.params.type = true;
						$(".bulk_foot .bulk_gz").html('<img src="../static/images/keep_r.png" alt="" /><span>已收藏</span>');
					}
				});
			},
			fllowMethod: function() { // 收藏或取消收藏
				if(vLoginClick()) {
					if(isFollow == '0') {
						this.item2.params.action = 1;
						this.$http.get(this.fllowUrl, this.item2)
						.then(function(response) {
							var result = JSON.parse(response.body);
							var success = result.data.success;
							if(success) {
								promptBox("收藏成功！");
								$(".bulk_foot .bulk_gz").html('<img src="../static/images/keep_r.png" alt="" /><span>已收藏</span>');
								isFollow = '1';
							}
						});
					} else {
						this.item2.params.action = 0;
						this.$http.get(this.fllowUrl, this.item2)
						.then(function(response) {
							var result = JSON.parse(response.body);
							var success = result.data.success;
							if(success) {
								promptBox("取消收藏！");
								$(".bulk_foot .bulk_gz").html('<img src="../static/images/keep_r1.png" alt="" /><span>收藏</span>');
								isFollow = '0';
							}
						});
					}
				}
			}
		}
	});
});